#include "SysMembers.h"



SysMembers::SysMembers()
{

}

void SysMembers::importALL()
{
    static int errCount = 0;
    while (!currentStatus.GetInit(MU_DEVICE_SQL)  ) {
        if(errCount < 5){
            sleep_s(3);
            errCount ++;
        }else {
            pushWarn("系统长时间无法进入完成状态!",MU_ERROR_MODULE_APP);
            pushExp(MU_Messages::App,MU_EXPS::EXP_APP_INIT_FALSE,MU_ERROR_MODULE_APP);
        }
    }
    initCads();
    initAllSeams();
    news.exchange(true);
    moduleInitDone();
}


string SysMembers::getDBPath()
{
    Fast::config t("etc/dbp/db.sys");
    std::string pp;
    int node = t.get<int>("dbpath");
    if(0 == node){
        pp = t.get<std::string>("WELD.dpath");      // 取焊接的数据库
    }else {
        pp = t.get<std::string>("LOCAL.dpath");      // 取调试的数据库
    }
    qDebug()<<pp.c_str();
    return  pp;
    //t.sync();
}

void SysMembers::update()
{
    importALL();
}

void SysMembers::initCads()
{
    QString query = "select cadid from cad";
    try{
        auto t = sqlProvider::GetInstance()->Get(query.toStdString());

        foreach(auto a,t){
            cads.push_back( a.toString());
        }

    }catch(...){
        qDebug()<<__FUNCTION__<<"获取CAD表失败!";
    }
}

void SysMembers::initAllSeams()
{
    auto t = sqlProvider::GetInstance()->Get("select seamid from seaminfo");  /* 双重筛选 */
    foreach (auto var, t) {
        seams.push_back(var.toString());
    }

    auto s = sqlProvider::GetInstance()->Get("select seamname from seaminfo");  /* 双重筛选 */
    foreach (auto var, t) {
        seaminfos.push_back(var.toString());
    }

}
